#!/usr/bin/python
# -*- coding:utf-8 -*-
# author : b1ng0

import json


from app import User


# 定义ORM
# class User(db.Model):
#     __tablename__ = 'data'
#     id = db.Column(db.Integer, primary_key=True)
#     role = db.Column(db.Integer) # 0 卫星 | 1 用户
#     userId = db.Column(db.String(255), unique=True)
#     userKey = db.Column(db.String(255), unique=True)
#     preRandom = db.Column(db.String(255), unique=True)
#     # random18：计算 userId 用，让用户idcard和 userId 一一对应，避免重复注册。
#     IDcard= db.Column(db.String(255), unique=True)
#     def __init__(self, role, userId, userKey, preRandom,IDcard):
#         self.role = role
#         self.userId = userId
#         self.userKey = userKey
#         self.preRandom = preRandom
#         self.IDcard=IDcard
#     def __repr__(self):
#         return '<Uid %r>' % self.userId


def  getAuthData(userId):
    user = User.query.filter_by(userId=userId).one()
    return {
        "userId": user.userId,
        "userKey": user.userKey,
        "preRandom": user.preRandom  
    }

def getAuthID(IDcard):
    user = User.query.filter_by(IDcard=IDcard).one()
    return json.dumps({
        "userId": user.userId,
        "userKey": user.userKey,
        "preRandom": user.preRandom,
        "status":'1'
    })